package com.mycjj.android.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.mycjj.android.R;
import com.mycjj.android.adapter.RecordAdapter;
import com.mycjj.android.bean.SyceeGetRecordBaseBean;
import com.mycjj.android.http.ProjectHttpRequestImpl;
import com.mycjj.android.http.ProjectHttpRequestInterface;
import com.mycjj.android.pullrefresh.PullToRefreshBase;
import com.mycjj.android.pullrefresh.PullToRefreshBase.OnRefreshListener;
import com.mycjj.android.pullrefresh.PullToRefreshListView;
import com.mycjj.android.util.Preferences;

public class GoldRecordAFragment extends BaseFragment{
	public static GoldRecordAFragment newInstance() {
		GoldRecordAFragment fragment = new GoldRecordAFragment();
        return fragment;
    }
	private View rootView;
	private PullToRefreshListView mListView;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = inflater.inflate(R.layout.fragment_main_new_car, null);
		mListView = (PullToRefreshListView)rootView.findViewById(R.id.lv_pull_refresh_list);
		mListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
			@Override
			public void onRefresh(PullToRefreshBase<ListView> refreshView) {
				//请求数据
				mListView.onRefreshComplete();//归原来
			}
		});
		return rootView;
	}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initData();
	}
	private void initData(){
		
		adapter = new RecordAdapter(getActivity(),"+");
		mListView.setAdapter(adapter);
		
		requestInterface = new ProjectHttpRequestImpl(getActivity(), true);
		RequestParams params = new RequestParams();
		params.put("type", "earn");
		params.put("limit", "100");
		params.put("offset", "0");
		params.put("client_id", ProjectHttpRequestInterface.client_id_key);
		params.put("token", Preferences.getSharedPreferences(getActivity(), "user_token", ""));
		requestInterface.requestSyceeGetRecordWithDoneHandler("",params,new AsyncHttpResponseHandler(){
			@Override
			public void onSuccess(String content) {
				SyceeGetRecordBaseBean baseBean = dataInstance.getGoldRecordBaseBean();
				if(baseBean != null){
					if(baseBean.getCode() == 200){
						if(baseBean.getData() != null){
							adapter.setList(baseBean.getData().getList());
						}else{
							Log.e("mark", "SyceeGetRecordBaseBean.getData() is null!");
						}
					}else{
						Toast.makeText(getActivity(), baseBean.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}else{
					Log.e("mark", "SyceeGetRecordBaseBean is null!");
				}
			}
		});
	}
	
	private RecordAdapter adapter;
	
	
}
